package com.shop.front.dao.pink;

import com.shop.jpa.BaseDao;
import com.shop.domain.pink.StorePink;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface StorePinkDao extends BaseDao<StorePink, Long> {

    @Modifying(clearAutomatically = true)
    @Query("update StorePink set status = ?2 where id = ?1 and status = ?3")
    public int updateStorePinkStatusById(Long id,int status, int lastStatus);

    @Query("select count(*) from StorePink where status = 1 and uid = ?1 and pinkId = ?2")
    public int countPinking(Long userId, Long pinkId);

    @Modifying(clearAutomatically = true)
    @Query("update StorePink set userAddressId = ?2, payType = ?3, payCode = ?4 where id = ?1")
    public int updateBySubmitOrder(Long id, Long userAddressId, String payType, Integer payCode);

    @Modifying(clearAutomatically = true)
    @Query("update StorePink set status = 1, payTime = now() where status = 0 and id = ?1 and orderNo = ?2 ")
    public int updateStatusByPaySuccess(Long id, String orderNo);

    public StorePink findByOrderNo(String orderNo);

    @Modifying(clearAutomatically = true)
    @Query("update StorePink set status = 4 where id = ?1 and status = ?2")
    public int updateByGetGoods(Long id, int lastStatus);

    @Modifying(clearAutomatically = true)
    @Query("update StorePink set status = 6 where id = ?1")
    public int updateByJishouSuccess(Long id);

    @Query("select count(*) from StorePink where uid = ?1 and status = ?2")
    public int countByUidAndStatus(Long userId, Integer status);

    @Modifying(clearAutomatically = true)
    @Query("update StorePink set status = ?2,rebate_status=?3,updateTime = now() where id = ?1 and status = ?4")
    public int updateStorePinkStatusAndRebateStatusById(Long id,int status,int rebateStatus, int lastStatus);
}
